<template>
	<view class="page" v-if="activityId > 0?true:false">
		<home-view v-show="tabList[current].type === 1" ref="page_view1" @getForm="getForm" :activityId="activityId">
		</home-view>
		<rule-view v-show="tabList[current].type === 2" ref="page_view2" :details="details" :prize='prize'>
		</rule-view>
		<view v-show="tabList[current].type === 3">
			<sign-up v-if="tabList.length == 5" ref="page_view3" :timeForm="timeForm" :activityId="activityId">
			</sign-up>
		</view>
		<rank-view v-show="tabList[current].type === 4" ref="page_view4" :timeForm="timeForm" :activityId="activityId">
		</rank-view>
		<my-mine  v-show="tabList[current].type === 5" ref="page_view5"  :activityId="activityId"></my-mine>
		<sww-login></sww-login>
		<u-tabbar v-if="tabList[0]?true:false" v-model="current" :list="tabList" :active-color="vuex_config.themeColor1"
			@change="onChange">
		</u-tabbar>
	</view>

</template>

<script>
	import {
		pageShare
	} from '@/mixins/pageShare.js';
	import homeVew from './pageComponents/home.vue'
	import signUp from './pageComponents/signUp.vue'
	import ruleView from './pageComponents/ruleView.vue'
	import rankView from './pageComponents/rank.vue'
	import myMine from './pageComponents/mine.vue'
	export default {
		mixins: [pageShare],
		components: {
			'home-view': homeVew,
			'rule-view': ruleView,
			'sign-up': signUp,
			'rank-view': rankView,
			myMine
		},
		data() {
			return {
				pageInit: false,
				activityId: null,
				timeForm: {},
				current: 0,
				details: '', // 规则
				prize:'',//活动奖励
				tabList: []
			}
		},
		onLoad(options) {
			this.activityId = Number(options.id)
			uni.setNavigationBarTitle({
				title: this.tabList[0] ? this.tabList[this.current].pageTitle : '首页'
			});
		},
		onShow() {
			if (!this.pageInit) {
				this.pageInit = true
				return
			}
			if (this.tabList[this.current].type === 1) {
				this.$refs.page_view1.$initPage();
			}
		},
		onReachBottom: function() {
			try {
				let str = 'page_view' + this.tabList[this.current].type;
				if (this.$refs[str].$onReachBottom) {
					this.$refs[str].$onReachBottom();
				}
			} catch (e) {}
		},
		// 微信小程序分享(好友)
		onShareAppMessage: function() {
			return this.getShareAppMessage();
		},
		onPullDownRefresh: function() {
			try {
				let str = 'page_view' + this.tabList[this.current].type;
				if (this.$refs[str].$onPullDownRefresh) {
					this.$refs[str].$onPullDownRefresh();
				}
			} catch (e) {}
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 700);
		},
		methods: {
			getForm(obj) {
				if (!this.tabList[0]) {
					this.details = obj.details
					this.prize = obj.prize
					let arr = [{
							text: '首页',
							pageTitle: '首页',
							iconPath: 'e63d',
							selectedIconPath: 'e63c',
							type: 1
						},
						{
							text: '规则',
							pageTitle: '规则',
							iconPath: 'e684',
							selectedIconPath: 'e684',
							type: 2
						},
						{
							text: '排行榜',
							pageTitle: '排行榜',
							iconPath: 'e69d',
							selectedIconPath: 'e69d',
							type: 4
						},
						{
							text: '我的',
							pageTitle: '我的',
							iconPath: 'e69d',
							selectedIconPath: 'e69d',
							type: 5
						},
					]
					if (obj.is_enroll == 1) {
						arr.splice(2, 0, {
							text: '我要参加',
							pageTitle: '我要参加',
							iconPath: 'e6d8',
							selectedIconPath: 'e6d8',
							type: 3
						})
					}
					this.tabList = [].concat(arr)
				}
				this.timeForm = {
					...obj
				}
			},
			onChange(index) {
				uni.pageScrollTo({
					scrollTop: 0
				})
				uni.setNavigationBarTitle({
					title: this.tabList[index].pageTitle
				});
				this.$nextTick(() => {
					let str = 'page_view' + this.tabList[index].type;
					if (this.$refs[str].init) {
						this.$refs[str].init();
					}
				});
			}
		}
	}
</script>
<style>
	page {
		background-color: #F5F5F5;
	}
</style>
<style lang="scss" scoped>
	.vote {}
</style>
